﻿using DevExpress.XtraBars;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Git
{
    partial class git
    {
        private bool gittexst = false;

        void p_gittest_OutputDataReceived(object sender, DataReceivedEventArgs e)
        {
            if (e.Data != null)
            {
                if (Regex.IsMatch(e.Data, "user.name"))
                {
                    gittexst = true;
                }
                Console.WriteLine(e.Data);
            }
        }

        public Boolean gittest(string file)
        {
            try
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;    //是否使用操作系统shell启动
                p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
                p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
                p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
                p.StartInfo.CreateNoWindow = true;//不显示程序窗口
                p.OutputDataReceived += p_gittest_OutputDataReceived;
                p.Start();
                p.StandardInput.WriteLine(@"cd """ + file + @"""");
                p.StandardInput.WriteLine("git config --list");
                p.StandardInput.WriteLine("exit");
                p.BeginOutputReadLine();
                p.WaitForExit();
                p.Close();
                return gittexst;
            }
            catch (Exception e) {
                return false;
            }
        }

    }
}
